package com.keste.model.emp.am;

import com.keste.model.emp.am.common.BuEmployeeAM;
import com.keste.model.emp.view.BuEmployeeVOImpl;

import java.util.HashMap;
import java.util.Map;

import oracle.jbo.Row;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewObject;
import oracle.jbo.domain.Number;
import oracle.jbo.server.ApplicationModuleImpl;
import oracle.jbo.server.ViewLinkImpl;
import oracle.jbo.server.ViewObjectImpl;

// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Mon Nov 24 15:41:52 IST 2014
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class BuEmployeeAMImpl extends ApplicationModuleImpl implements BuEmployeeAM {
    /**
     * This is the default constructor (do not remove).
     */
    Map currentAddrOldValuesMap = new HashMap();
    Number manager_id, department_id;
    String employee_role_code;

    public BuEmployeeAMImpl() {
    }

    /**
     * Container's getter for Employee.
     * @return Employee
     */
    public BuEmployeeVOImpl getEmployee() {
        return (BuEmployeeVOImpl)findViewObject("Employee");
    }

    /**
     * Container's getter for Address.
     * @return Address
     */
    public ViewObjectImpl getAddress() {
        return (ViewObjectImpl)findViewObject("Address");
    }

    /**
     * Container's getter for Education.
     * @return Education
     */
    public ViewObjectImpl getEducation() {
        return (ViewObjectImpl)findViewObject("Education");
    }

    /**
     * Container's getter for Department.
     * @return Department
     */
    public ViewObjectImpl getDepartment() {
        return (ViewObjectImpl)findViewObject("Department");
    }

    /**
     * Container's getter for BuLookupVO.
     * @return BuLookupVO
     */
    public ViewObjectImpl getBuLookupVO() {
        return (ViewObjectImpl)findViewObject("BuLookupVO");
    }

    /**
     * Container's getter for AddressCurr.
     * @return AddressCurr
     */
    public ViewObjectImpl getAddressCurr() {
        return (ViewObjectImpl)findViewObject("AddressCurr");
    }

    /**
     * Container's getter for AddressPerm.
     * @return AddressPerm
     */
    public ViewObjectImpl getAddressPerm() {
        return (ViewObjectImpl)findViewObject("AddressPerm");
    }

    /**
     * Container's getter for EmployeeToAddressVL.
     * @return EmployeeToAddressVL
     */
    public ViewLinkImpl getEmployeeToAddressVL() {
        return (ViewLinkImpl)findViewLink("EmployeeToAddressVL");
    }

    /**
     * Container's getter for EmployeeToEducationVL.
     * @return EmployeeToEducationVL
     */
    public ViewLinkImpl getEmployeeToEducationVL() {
        return (ViewLinkImpl)findViewLink("EmployeeToEducationVL");
    }

    /**
     * Container's getter for EmployeeToAddressCurrVL.
     * @return EmployeeToAddressCurrVL
     */
    public ViewLinkImpl getEmployeeToAddressCurrVL() {
        return (ViewLinkImpl)findViewLink("EmployeeToAddressCurrVL");
    }

    /**
     * Container's getter for EmployeeToAddressPermVL.
     * @return EmployeeToAddressPermVL
     */
    public ViewLinkImpl getEmployeeToAddressPermVL() {
        return (ViewLinkImpl)findViewLink("EmployeeToAddressPermVL");
    }


    public void onCheckAction(Boolean checkFlag, int count) {
        ViewObject currentAddressVO = getAddressCurr();
        ViewObject permanantAddressVO = getAddressPerm();
        if (count == 1) {
            currentAddrOldValuesMap.put("AddressLine1",
                                        currentAddressVO.getCurrentRow().getAttribute("AddressLine1"));
            currentAddrOldValuesMap.put("AddressLine2",
                                        currentAddressVO.getCurrentRow().getAttribute("AddressLine2"));
            currentAddrOldValuesMap.put("AddressLine3",
                                        currentAddressVO.getCurrentRow().getAttribute("AddressLine3"));
            currentAddrOldValuesMap.put("City",
                                        currentAddressVO.getCurrentRow().getAttribute("City"));
            currentAddrOldValuesMap.put("Country",
                                        currentAddressVO.getCurrentRow().getAttribute("Country"));
            currentAddrOldValuesMap.put("ZipCode",
                                        currentAddressVO.getCurrentRow().getAttribute("ZipCode"));
            currentAddrOldValuesMap.put("StateProvince",
                                        currentAddressVO.getCurrentRow().getAttribute("StateProvince"));
            System.out.println(currentAddrOldValuesMap);
        }
        if (checkFlag) {
            currentAddressVO.getCurrentRow().setAttribute("AddressLine1",
                                                          permanantAddressVO.getCurrentRow().getAttribute("AddressLine1"));
            currentAddressVO.getCurrentRow().setAttribute("AddressLine2",
                                                          permanantAddressVO.getCurrentRow().getAttribute("AddressLine2"));
            currentAddressVO.getCurrentRow().setAttribute("AddressLine3",
                                                          permanantAddressVO.getCurrentRow().getAttribute("AddressLine3"));
            currentAddressVO.getCurrentRow().setAttribute("City",
                                                          permanantAddressVO.getCurrentRow().getAttribute("City"));
            currentAddressVO.getCurrentRow().setAttribute("Country",
                                                          permanantAddressVO.getCurrentRow().getAttribute("Country"));
            currentAddressVO.getCurrentRow().setAttribute("ZipCode",
                                                          permanantAddressVO.getCurrentRow().getAttribute("ZipCode"));
            currentAddressVO.getCurrentRow().setAttribute("StateProvince",
                                                          permanantAddressVO.getCurrentRow().getAttribute("StateProvince"));
        } else {
            currentAddressVO.getCurrentRow().setAttribute("AddressLine1",
                                                          currentAddrOldValuesMap.get("AddressLine1"));
            currentAddressVO.getCurrentRow().setAttribute("AddressLine2",
                                                          currentAddrOldValuesMap.get("AddressLine2"));
            currentAddressVO.getCurrentRow().setAttribute("AddressLine3",
                                                          currentAddrOldValuesMap.get("AddressLine3"));
            currentAddressVO.getCurrentRow().setAttribute("City",
                                                          currentAddrOldValuesMap.get("City"));
            currentAddressVO.getCurrentRow().setAttribute("Country",
                                                          currentAddrOldValuesMap.get("Country"));
            currentAddressVO.getCurrentRow().setAttribute("ZipCode",
                                                          currentAddrOldValuesMap.get("ZipCode"));
            currentAddressVO.getCurrentRow().setAttribute("StateProvince",
                                                          currentAddrOldValuesMap.get("StateProvince"));
        }
    }

    public Row[] getFilteredEmployees(String string) {
        String[] strArray = string.split("\\s+");
        BuEmployeeVOImpl empVO = this.getEmployee();
        empVO.applyViewCriteria(null);
        empVO.setApplyViewCriteriaName("searchByEmployeeNameEmailContact");
        empVO.setpFirstName(strArray[strArray.length - 1]);
        empVO.setpMidName(strArray[strArray.length - 1]);
        empVO.setpLastName(strArray[strArray.length - 1]);
        empVO.setpEmailId(strArray[strArray.length - 1]);
        empVO.setpMobile(strArray[strArray.length - 1]);
        empVO.setpPhone(strArray[strArray.length - 1]);
        empVO.setpManagerId(this.getManager_id());
        empVO.setpDepartmentId(this.getDepartment_id());
        empVO.setpEmployeeRole(this.getEmployee_role_code());
        empVO.executeQuery();
        empVO.setQueryMode(ViewObject.QUERY_MODE_SCAN_VIEW_ROWS);
        ViewCriteria vc = empVO.getViewCriteria("searchByEquality");
        vc.setCriteriaMode(ViewCriteria.CRITERIA_MODE_CACHE);
        for (int i = 0; i < strArray.length - 1; i++) {
            empVO.setpFirstName(strArray[i]);
            empVO.setpMidName(strArray[i]);
            empVO.setpLastName(strArray[i]);
            empVO.setpEmailId(strArray[i]);
            empVO.setpMobile(strArray[i]);
            empVO.setpPhone(strArray[i]);
            empVO.applyViewCriteria(vc);
            empVO.setpManagerId(this.getManager_id());
            empVO.setpDepartmentId(this.getDepartment_id());
            empVO.setpEmployeeRole(this.getEmployee_role_code());
            empVO.executeQuery();
        }
        empVO.setQueryMode(ViewObject.QUERY_MODE_SCAN_DATABASE_TABLES);
        return empVO.getAllRowsInRange();
    }

    public void onSelectEmployee(Number empId) {
        BuEmployeeVOImpl empVO = this.getEmployee();
        empVO.applyViewCriteria(null);
        empVO.setApplyViewCriteriaName("searchByEmployeeId");
        empVO.setpEmployeeId(empId);
        empVO.executeQuery();
    }

    public void onResetEmployeeSearch() {
        BuEmployeeVOImpl empVO = this.getEmployee();
        empVO.applyViewCriteria(null);
        empVO.setpFirstName(null);
        empVO.setpMidName(null);
        empVO.setpLastName(null);
        empVO.setpEmailId(null);
        empVO.setpMobile(null);
        empVO.setpPhone(null);
        empVO.setpManagerId(null);
        empVO.setpDepartmentId(null);
        this.setDepartment_id(null);
        this.setManager_id(null);
        this.setEmployee_role_code(null);
        empVO.executeQuery();
    }

    /**
     * Container's getter for EmployeeSearchTransient.
     * @return EmployeeSearchTransient
     */
    public ViewObjectImpl getEmployeeSearchTransient() {
        return (ViewObjectImpl)findViewObject("EmployeeSearchTransient");
    }

    /**
     * Container's getter for CompanyVO.
     * @return CompanyVO
     */
    public ViewObjectImpl getCompanyVO() {
        return (ViewObjectImpl)findViewObject("CompanyVO");
    }

    /**
     * Container's getter for BuEMployeeVoToCompanyVOVL1.
     * @return BuEMployeeVoToCompanyVOVL1
     */
    public ViewLinkImpl getBuEMployeeVoToCompanyVOVL1() {
        return (ViewLinkImpl)findViewLink("BuEMployeeVoToCompanyVOVL1");
    }

    /**
     * Container's getter for BuAwardsVO1.
     * @return BuAwardsVO1
     */
    public ViewObjectImpl getBuAwardsVO() {
        return (ViewObjectImpl)findViewObject("BuAwardsVO");
    }

    /**
     * Container's getter for BuEmployeeVOToBuAwardsVOVL1.
     * @return BuEmployeeVOToBuAwardsVOVL1
     */
    public ViewLinkImpl getBuEmployeeVOToBuAwardsVOVL1() {
        return (ViewLinkImpl)findViewLink("BuEmployeeVOToBuAwardsVOVL1");
    }

    /**
     * Container's getter for BuSkillsetsVO.
     * @return BuSkillsetsVO
     */
    public ViewObjectImpl getBuSkillsetsVO() {
        return (ViewObjectImpl)findViewObject("BuSkillsetsVO");
    }

    /**
     * Container's getter for BuEmployeeVOToBuSkillsetsVOVL1.
     * @return BuEmployeeVOToBuSkillsetsVOVL1
     */
    public ViewLinkImpl getBuEmployeeVOToBuSkillsetsVOVL1() {
        return (ViewLinkImpl)findViewLink("BuEmployeeVOToBuSkillsetsVOVL1");
    }

    /**
     * Container's getter for BuEmployeeProjectsVO.
     * @return BuEmployeeProjectsVO
     */
    public ViewObjectImpl getBuEmployeeProjectsVO() {
        return (ViewObjectImpl)findViewObject("BuEmployeeProjectsVO");
    }

    /**
     * Container's getter for CompanyVOToBuEmployeeProjectsVOVL1.
     * @return CompanyVOToBuEmployeeProjectsVOVL1
     */
    public ViewLinkImpl getCompanyVOToBuEmployeeProjectsVOVL1() {
        return (ViewLinkImpl)findViewLink("CompanyVOToBuEmployeeProjectsVOVL1");
    }

    public void setManager_id(Number manager_id) {
        this.manager_id = manager_id;
    }

    public Number getManager_id() {
        return manager_id;
    }

    public void setDepartment_id(Number department_id) {
        this.department_id = department_id;
    }

    public Number getDepartment_id() {
        return department_id;
    }

    public void setEmployee_role_code(String employee_role_code) {
        this.employee_role_code = employee_role_code;
    }

    public String getEmployee_role_code() {
        return employee_role_code;
    }
}
